%      _____      _____     _____      ______
%     /\  _  \   /\  ___\  /\  _  \   /\__  __\
%     \ \ \_\ \  \ \ \___  \ \ \_\ \  \/_/\ \_/
%      \ \  ___\  \ \___ \  \ \  __ \    \ \ \
%       \ \ \__/   \/___\ \  \ \ \ \ \    \ \ \
%        \ \_\      /\_____\  \ \_\ \_\    \ \_\
%         \/_/      \/_____/   \/_/\/_/     \/_/
%
% Copyright (C) 2002-2019 Federico Milano
%
% PSAT is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This toolbox is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANDABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
% General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with PSAT.  If not, see <http://www.gnu.org/license/>.

echo off
if exist('command_line_psat') ~= 1
  clear classes
  clear all
  clear global
  command_line_psat = 0;
  if exist('OCTAVE_VERSION')
    command_line_psat = 1;
  end
end

%PSAT Power System Analysis Toolbox
%
%Author:    Federico Milano
%Date:      11-Nov-2002
%Update:    06-Mar-2007
%
%E-mail:    federico.milano@ucd.ie
%Web-site:  faraday1.ucd.ie/psat.html

% check host version
a = version;
a = str2num(a(1:3));
if ~exist('OCTAVE_VERSION')
  if a < 5.3
    disp('PSAT needs a Matlab version >= 5.3')
    return
  elseif a < 7.0
    disp(['For Matlab versions < 7.0, PSAT runs only ' ...
          'in the command line mode'])
    command_line_psat = 1;
  end
end

psatver = '2.1.11';
psatdate = 'August 17, 2019';

failed = 0;
disp(' ')
disp('                        < P S A T >')
disp('          Copyright (C) 2002-2019 Federico Milano')
disp([blanks(30-floor(5+length(psatver)/2)),'Version ',psatver])
disp([blanks(30-ceil(length(psatdate)/2)),psatdate])
disp('  ')
disp('PSAT comes with ABSOLUTELY NO WARRANTY; type ''gnuwarranty''')
disp('for details. This is free software, and you are welcome to')
disp(['redistribute it under certain conditions; type' ...
      ' ''gnulicense'''])
disp('for details.')
disp('  ')
if exist('OCTAVE_VERSION')
  disp(['Host:         Octave ',version])
else
  disp(['Host:         Matlab ',version])
end
disp(['Session:      ', datestr(now,0)])
if command_line_psat
  disp('Usage:        Command Line')
else
  disp('Usage:        Graphical User Interface')
end
disp(['Path:         ',pwd])
disp(' ')

% searching the "PSAT" path
psatdir = which('psat.m');
psatdir = psatdir(1:end-7);
if strcmp(psatdir,'.'), psatdir = pwd; end

% check for Octave
if exist('OCTAVE_VERSION') && isempty(findstr(path,[psatdir,filesep,'@BUclass']))
  folders = dir([psatdir,filesep,'@*']);
  for i = length(folders):-1:1
    if folders(i).isdir
      addpath([psatdir,filesep,folders(i).name])
    end
  end
  addpath([psatdir,filesep,'filters'])
  addpath(psatdir)
  clear folders
end

% check for Matlab
if isempty(strmatch(path,[psatdir,filesep,'filters'],'exact'))
  addpath([psatdir,filesep,'filters'])
end
if isempty(strmatch(path,psatdir,'exact'))
  addpath(psatdir)
end

fm_var

Path = struct('data','','local','','psat','','pert','', ...
              'build','','images','','themes','', ...
              'filters','','temp','');

if command_line_psat
  clpsat.init = 1;
  clpsat.mesg = 1;
  clpsat.refresh = 1;
  clpsat.refreshsim = 0;
  clpsat.readfile = 1;
  clpsat.showopf = 0;
  clpsat.pq2z = 1;
  clpsat.viewrep = 0;
else
  clpsat.init = 0;
  clpsat.mesg = 1;
  clpsat.refresh = 0;
  clpsat.refreshsim = 0;
  clpsat.readfile = 1;
  clpsat.showopf = 1;
  clpsat.pq2z = 1;
  clpsat.viewrep = 1;
end

Path.local = [pwd,filesep];
if exist('OCTAVE_VERSION')
  Path.psat = strrep(which('psat'),'psat.m','');
else
  if strncmp(computer,'GLNX',4)
    Path.local = strrep(Path.local,'~',getenv('HOME'));
  end
  Path.psat = [psatdir,filesep];
  if strcmp(computer,'GLNX86')
    Path.psat = strrep(Path.psat,'~',getenv('HOME'));
  end
end
Path.build   = [Path.psat,'build',  filesep];
Path.images  = [Path.psat,'images', filesep];
Path.themes  = [Path.psat,'themes', filesep];
Path.filters = [Path.psat,'filters',filesep];

if exist(Path.build) ~= 7
  disp('No "build" folder found in the current PSAT path.')
  failed = ~mkdir(Path.psat,'build');
  if failed,
    disp('The folder "build" could not be created')
  end
end
if exist(Path.images) ~= 7
  disp('No "images" folder found in the current PSAT path.')
  failed = 1;
end
if exist(Path.themes) ~= 7
  disp('No "themes" folder found in the current PSAT path.')
  failed = ~mkdir(Path.psat,'themes');
  if failed,
    disp('The folder "themes" could not be created')
  end
end
if exist(Path.filters) ~= 7
  disp('No "filters" folder found in the current PSAT path.')
  failed = 1;
end
if failed
  disp('The PSAT folder seems to be uncomplete and needs to be installed again.')
  disp('PSAT initialization failed.')
  return
end

if ~command_line_psat
  [hdl,htxt] = fm_enter(psatdir,psatver,psatdate);
  pause(0.1)
  hold on
  % the size of the splash window are 346 x 410 pixels
  if version < 8
    hdlp = patch([8 8 41 41 8],[405 395 395 405 405], ...
                 [0.50 0.45 0.95],'EdgeColor',[1 1 1]);
    set(hdlp,'EraseMode','none');
  else
    hdlp = patch([8 8 41 41 8],[5 15 15 5 5], ...
                 [0.50 0.45 0.95],'EdgeColor',[1 1 1]);
  end
  set(htxt,'Color',[0.4 0.4 0.4],'String','Initializing History...')
  drawnow
end

File = struct('data','','pert','','temp','','modify','');
Source = struct('data','','pert','','description','');

jay = sqrt(-1);

History = struct('text','', ...
                 'index',1, ...
                 'string','', ...
                 'workspace',0, ...
                 'Max',500, ...
                 'FontName', ...
                 'Courier', ...
                 'FontSize',12, ...
                 'FontAngle','normal', ...
                 'FontWeight','normal', ...
                 'BackgroundColor','w', ...
                 'ForegroundColor','k');

History.text = {['PSAT version ',psatver, ...
		 ', Copyright (C) 2002-2019 Federico Milano']; ...
		' '; ['Session  ', datestr(now)]};

if ~command_line_psat
  set(hdlp,'XData',[8 8 74 74 8])
  set(htxt,'String','Initializing Settings...')
  drawnow
end

try
  settings()
catch
  Theme = struct('color01',[0.800 0.800 0.800], ...
                 'color02',[0.753 0.753 0.753], ...
                 'color03',[0.502 0.502 0.502], ...
                 'color04',[1.000 1.000 1.000], ...
                 'color05',[0.000 0.000 0.502], ...
                 'color06',[1.000 1.000 0.502], ...
                 'color07',[0.502 0.000 0.000], ...
                 'color08',[0.750 0.390 0.503], ...
                 'color09',[1.000 1.000 1.000], ...
                 'color10',[1.000 1.000 1.000], ...
                 'color11',[0.920 0.920 0.920], ...
                 'font01','Courier','hdl',zeros(18,1));

  Settings = struct( ...
      'pq2z',0, ...
      'pv2pq',0, ...
      'pv2pqniter',0, ...
      'multipvswitch',0, ...
      'showlf',0, ...
      'init', 0, ...
      'status', 1, ...
      'conv', 1, ...
      'plot',0, ...
      'plottype',1, ...
      'method',2, ...
      'show',1, ...
      'vs',0, ...
      'ok',0, ...
      'pfsolver', 1, ...
      'deltadelta',180, ...
      'checkdelta',0, ...
      'deltat',1e-5, ...
      'deltatmax',1e-3, ...
      'deltatmin',1e-5, ...
      'chunk',100, ...
      'maxvar',1500, ...
      'maxsimout', 15, ...
      'maxsimin', 15, ...
      'mv',0, ...
      'nseries',0, ...
      'iter',0, ...
      'static', 0, ...
      'zoom','', ...
      'freq', 50, ...
      'beep',0, ...
      'dyntol',1e-5, ...
      'dynmit',20, ...
      'lftol',1e-5, ...
      'lfmit',20, ...
      'lftime', 0, ...
      't0',0, ...
      'tf',30, ...
      'mva',100, ...
      'rad',2*3.14159265358979*50, ...
      'distrsw', 0, ...
      'color',[], ...
      'fixt',0, ...
      'tstep',0.001, ...
      'xlabel','time (s)', ...
      'locksnap',0, ...
      'tviewer',[], ...
      'absvalues', 'off', ...
      'violations', 'off', ...
      'error', 1, ...
      'export','txt', ...
      'noarrows',1, ...
      'matlab',1, ...
      'octave',0, ...
      'local',1, ...
      'simtd',0, ...
      'forcepq',0, ...
      'switch2nr',0, ...
      'resetangles',1, ...
      'format',1, ...
      'coi',0, ...
      'platform','UNIX', ...
      'report',0, ...
      'donotask',0, ...
      'usedegree',0, ...
      'usehertz',0, ...
      'userelspeed',0);
end

Settings.color = [0      0      1.0000;
                  0      0.5000 0;
                  1.0000 0      0;
                  0      0.7500 0.7500;
                  0.7500 0      0.7500;
                  0.7500 0.7500 0;
                  0.2500 0.2500 0.2500];

if ~command_line_psat
  set(0,'DefaultUicontrolBackgroundColor', Theme.color01)
end
a = version;
idx = findstr(a, '.');
Settings.hostver = str2num(a(1:idx(1)-1)) + 0.01*str2num(a(idx(1)+1:idx(2)-1));
Settings.init = 0;
Settings.donotask = 0;
Settings.version = psatver;
Settings.date = psatdate;
if exist('OCTAVE_VERSION')
  Settings.octave = 1;
  Settings.matlab = 0;
else
  Settings.octave = 0;
  Settings.matlab = 1;
end

if ~isfield(Settings,'local')
  Settings.local = 1;
end

if isunix && strcmp(Settings.export,'xls')
  Settings.export = 'txt';
end

switch computer
 case 'PCWIN'
  Settings.tviewer = '!notepad ';
 otherwise
  Settings.tviewer = '!cat ';
end

if Settings.octave
  Settings.platform = computer;
else
  if strncmp(computer,'PC',2)
    Settings.platform = 'PC';
  elseif strncmp(computer,'MAC',3) && usejava('jvm')
    Settings.platform = 'MAC';
  else
    Settings.platform = 'UNIX';
  end

  % avoid annoying warning message of Simulink models
  if Settings.hostver >= 9.05
    % warning('off','Simulink:Engine:InvalidDomainRegistrationKey');
    warning('off','all');
  end
  
  % Use default colors if the Java Desktop is in use
  if Settings.hostver >= 6.1
    if usejava('jvm')
      Theme.color01 = get(0,'factoryUicontrolBackgroundColor');
      Theme.color02 = get(0,'factoryUicontrolBackgroundColor');
      Theme.color03 = get(0,'factoryUicontrolBackgroundColor');
      if Settings.hostver < 8.04
        Theme.color04 = get(0,'factoryAxesXColor');
      else
        Theme.color04 = [1, 1, 1];
      end
      Theme.color05 = get(0,'factoryUicontrolForegroundColor');
      Theme.color06 = get(0,'factoryUicontrolForegroundColor');
      Theme.color07 = get(0,'factoryUicontrolForegroundColor');
      Theme.color09 = get(0,'factoryUicontrolForegroundColor');
      Theme.color10 = get(0,'factoryUicontrolForegroundColor');
      Theme.color11 = Theme.color04;
      if Settings.platform(1:2) ~= 'PC'
        Theme.font01 = get(0,'factoryTextFontName');
        Theme.font02 = get(0,'factoryTextFontName');
        Theme.font03 = get(0,'factoryTextFontName');
        Theme.font04 = get(0,'factoryTextFontName');
      end
    end
  end
end

Hdl = struct('hist',-1, ...
             'text',-1, ...
             'status',-1, ...
             'frame',-1, ...
             'bar',-1, ...
             'pert','');

if Settings.hostver >= 6
  Hdl.pert = str2func('pert');
else
  Hdl.pert = 'pert';
end

Fig = struct('main',-1, ...
             'plot',-1, ...
             'update',-1, ...
             'hist',-1, ...
             'pset',-1, ...
             'make',-1, ...
             'lib',-1, ...
             'comp',-1, ...
             'cset',-1, ...
             'sset',-1, ...
             'xset',-1, ...
             'eigen',-1, ...
             'matrx',-1, ...
             'theme',-1, ...
             'simset',-1, ...
             'setting',-1, ...
             'snap',-1, ...
             'stat',-1, ...
             'pmu',-1, ...
             'dir',-1, ...
             'cpf',-1, ...
             'snb',-1, ...
             'about',-1, ...
             'author',-1, ...
             'opf',-1, ...
             'line',-1, ...
             'clock',-1, ...
             'license',-1, ...
             'warranty',-1, ...
             'tviewer',-1, ...
             'gams',-1, ...
             'uwpflow',-1, ...
             'laprint',-1, ...
             'plotsel',-1, ...
             'threed',-1, ...
             'equiv',-1, ...
             'bus',-1, ...
             'advanced',-1);

% Component Structures
% clear Comp
Comp.prop = [];
Comp.n = 0;
Comp.init = 0;
Comp.descr = '';
Comp.name = '';
Comp.shunt = 1;
Comp.series = 0;

if ~command_line_psat
  set(hdlp,'XData',[8 8 107 107 8])
  set(htxt,'String','Initializing "namevar[xy].ini"...')
  drawnow
end

% Output Variables and Names Structures
Varout = struct('t',[],'vars',[],'idx',[],'surf',0,'hdl',[],'zlevel',0, ...
                'movie',[],'alpha',1,'caxis',0,'xb',[],'yb',[]);
Varname = struct('compx','','unamex','','fnamex','', ...
                 'compy','','unamey','','fnamey','', ...
                 'uvars','','fvars','','nvars',0, ...
                 'idx',[],'custom',0,'fixed',1, ...
                 'x',1,'y',1,'P',0,'Q',0, ...
                 'Pij',0,'Qij',0,'Iij',0,'Sij',0,'pos',[], ...
                 'areas',0,'regions',0);

% Snapshots
Snapshot = struct('name','', 'time',Settings.t0, ...
                  'y',[], 'x', [], 'Ybus', [], 'Pg', [], ...
                  'Qg', [], 'Pl', [], 'Ql', [],  ...
                  'Gy', [], 'Fx', [], 'Fy', [], 'Gx', [], ...
                  'Ploss', [], 'Qloss', [], 'it', 0);

filemode = 'rt';

% State variable names
fid = fopen([Path.psat,'namevarx.ini'],filemode);
if fid == -1,
  disp('#Error: File "namevarx.ini" cannot be open.')
  failed = 1;
else
  nname = 0;
  while 1
    sline = fgetl(fid);
    if ~ischar(sline), break; end
    try
      Varname.unamex{nname+1,1} = deblank(sline(1:20));
      Varname.fnamex{nname+1,1} = deblank(sline(21:40));
      Varname.compx{nname+1,1}  = deblank(sline(41:end));
      if Settings.octave && strcmp(Varname.compx{nname+1,1}(end),'\r')
        Varname.compx{nname+1,1} = Varname.compx{nname+1,1}(1:end-1);
      end
      nname = nname + 1;
    catch
      % nothing to do ...
    end
  end
  count = fclose(fid);
end

% Algebraic variable names
fid = fopen([Path.psat,'namevary.ini'],filemode);
if fid == -1,
  disp('#Error: File "namevary.ini" cannot be open.')
  failed = 1;
else
  nname = 0;
  while 1
    sline = fgetl(fid);
    if ~ischar(sline), break; end
    try
      Varname.unamey{nname+1,1} = deblank(sline(1:20));
      Varname.fnamey{nname+1,1} = deblank(sline(21:40));
      Varname.compy{nname+1,1}  = deblank(sline(41:end));
      if Settings.octave && strcmp(Varname.compy{nname+1,1}(end),'\r')
        Varname.compx{nname+1,1} = Varname.compy{nname+1,1}(1:end-1);
      end
      nname = nname + 1;
    catch
      % nothing to do ...
    end
  end
  count = fclose(fid);
end

if ~command_line_psat
  set(hdlp,'XData',[8 8 140 140 8])
  set(htxt,'String','Initializing "history.ini"...')
  drawnow
end

fid = fopen([Path.psat,'history.ini'],filemode);
if fid == -1,
  disp('#Error: File "history.ini" cannot be open.')
  failed = 1;
else
  while 1
    sline = fgetl(fid);
    if Settings.octave
      sline = sline(1:end-1);
    end
    if ~ischar(sline), break, end
    try
      eval(['History.',sline(1:19),' = ',sline(20:end),';']);
    catch
      % nothing to do ...
    end
  end
  count = fclose(fid);
end

if ~command_line_psat
  set(hdlp,'XData',[8 8 173 173 8])
  set(htxt,'String','Initializing "comp.ini"...')
  drawnow
end

% Existing components functions
fid = fopen([Path.psat,'comp.ini'],filemode);
if fid == -1,
  disp('#Error: File "comp.ini" cannot be open.')
  failed = 1;
else
  ncomp=0;
  while 1
    sline = fgetl(fid);
    if ~ischar(sline), break; end
    try
      Comp.names{ncomp+1,1} = deblank(sline(1:21));
      Comp.prop(ncomp+1,:) = str2num(sline(22:38));
      ncomp = ncomp + 1;
    catch
      % nothing to do ...
    end
  end
  count = fclose(fid);
  Comp.names{ncomp+1}  = 'PV';
  Comp.prop(ncomp+1,:) = [2 1 0 1 0 1 0 0 0];
  Comp.names{ncomp+2}  = 'SW';
  Comp.prop(ncomp+2,:) = [2 1 0 1 0 1 0 0 0];
  Comp.n = ncomp + 2;
end

if ~command_line_psat
  set(hdlp,'XData',[8 8 206 206 8])
  set(htxt,'String','Initializing global structures...')
  drawnow
end

if ~isunix && Settings.hostver >= 7 && sum(Theme.color09) < 0.3
  Theme.color09 = [0 0 0];
end

% Differential Algebraic Equations structure
DAE = struct('x',[], ...
             'y',[], ...
             'kg',0, ...
             'lambda',0, ...
             'm',0, ...
             'n',0, ...
             'npf',0, ...
             'g',[], ...
             'f',[], ...
             'Gy',[], ...
             'Fx',[], ...
             'Fy',[], ...
             'Fl',[], ...
             'Fk',[], ...
             'Gx',[], ...
             'Gl',[], ...
             'Gk',[], ...
             'Ac',[], ...
             'tn',[], ...
	     't', -1);

% Small Signal Stability Analysis (SSSA) paramters
SSSA = struct('neig',1,'method',1,'map',1,'matrix',4, ...
              'report',[],'eigs',[],'pf',[]);

% Limit-induced bifurcation (LIB) parameters
LIB = struct('type',1,'init',0,'selbus',1, ...
             'slack',0,'lambda',0,'dldp',[],'bus',[]);

% Saddle-node bifurcation (SNB) parameters
SNB = struct('slack',0,'init',0,'lambda',0,'dldp',[],'bus',[]);

% Continuation Power Flow structure
CPF = struct('method',1,'flow',1,'type',1,'sbus',1, ...
             'vlim',0,'ilim',0,'qlim',0,'init',0, ...
             'tolc',1e-5,'tolf',0.01,'tolv',5e-3, ...
             'step',0.5,'nump',50,'show',1,'linit',0, ...
             'lambda',0,'kg',0,'hopf',0,'stepcut',1,...
             'negload',0,'onlynegload',0,'onlypqgen',0, ...
             'areaannualgrowth',0,'regionannualgrowth',0);

% Optimal Power Flow structure
OPF = struct('method',2, ...
             'flow',1, ...
             'type',1, ...
             'deltat',30, ...
             'lmin',0.1, ...
             'lmax',0.8, ...
             'sigma',0.2, ...
             'gamma',0.95, ...
             'eps_mu',1e-10, ...
             'eps1',1e-4, ...
             'eps2',5e-3, ...
             'omega',0, ...
             'omega_s','0', ...
             'lmin_s','0.1', ...
             'fun','', ...
             'flatstart',1, ...
             'conv',0, ...
             'guess',[], ...
             'report',[], ...
             'show',1, ...
             'init',0, ...
             'w',0, ...
             'wp',[], ...
             'atc',0, ...
             'line',0, ...
             'tiebreak',0, ...
             'basepg',1, ...
             'basepl',1, ...
             'enflow',1, ...
             'envolt',1, ...
             'enreac',1, ...
             'vmin', 0.8, ...
             'vmax', 1.2, ...
             'obj',0, ...
             'ms',0, ...
             'dy',0, ...
             'dF',0, ...
             'dG',0, ...
             'LMP',[], ...
             'NCP',[], ...
             'iter',0, ...
             'gpc',[], ...
             'gqc',[]);

OMIB = struct('cm',[],'ncm',[],'mt',[],'pmax',[],'pc',[], ...
              'sig',[],'du',[],'tu',[],'margin',0);

PMU = struct('method',1, ...
             'number',0, ...
             'report','', ...
             'measv',0, ...
             'measc',0, ...
             'pseudo',0, ...
             'noobs',0, ...
             'voltage', '', ...
             'angle', '', ...
             'location', '');

% GAMS interface structure
GAMS = struct('method',2, ...
              'type',1, ...
              'flow',1, ...
              'flatstart',1, ...
              'lmin', 0.1, ...
              'lmin_s','0.1', ...
              'omega',0, ...
              'omega_s','0', ...
              'lmax',0.8, ...
              'libinclude', 0, ...
              'loaddir',1, ...
              'basepl',1, ...
              'basepg',1, ...
              'line',0, ...
              'show',1);

GAMS.ldir = ['ldir ',char(92),'~/psat/gams'];

% UWPFLOW interface
UWPFLOW = struct('opt',[],'method',1,'file','psatuw', ...
                 'command','','status',0);

% Structure for libraries
LA = struct( ...
    'a',[], ...
    'b_avr',[], 'b_tg',[], 'b_svc',[], 'b_statcom',[], ...
    'b_tcsc',[], 'b_sssc',[], 'b_upfc',[], 'b_hvdc',[], ...
    'c_y',[], ...
    'd_y',[], ...
    'd_avr',[], 'd_tg',[], 'd_svc',[], 'd_statcom',[], ...
    'd_tcsc',[], 'd_sssc',[], 'd_upfc',[], 'd_hvdc',[], ...
    'h_ps',[], 'h_qs',[], 'h_is',[], 'h_pr',[], 'h_qr',[], 'h_ir',[]);
EQUIV = struct( ...
    'buslist',[], ...
    'custom_file','', ...
    'custom_path','', ...
    'equivalent_method',1, ...
    'area_num',1, ...
    'region_num',1, ...
    'bus_selection',1, ...
    'bus_depth',0, ...
    'bus_voltage',220, ...
    'island', 0, ...
    'gentype', 1, ...
    'stop_island',0);

if ~command_line_psat
  set(hdlp,'XData',[8 8 239 239 8])
  set(htxt,'String','Initializing classes...')
  drawnow
end

% Component classes & structures
Bus = BUclass;
Areas = ARclass('area');
Regions = ARclass('region');
SW = SWclass;
PV = PVclass;
PQ = PQclass;
Line = LNclass;
Lines = LSclass;
Twt = TWclass;
Shunt = SHclass;
PQgen = PQclass;
Demand = DMclass;
Supply = SUclass;
Fault = FTclass;
Breaker = BKclass;
Fl = FLclass;

if ~command_line_psat
  set(hdlp,'XData',[8 8 272 272 8])
  drawnow
end

Mn = MNclass;
Pl = PLclass;
Ind = IMclass;
Thload = THclass;
Ltc = LTclass;
Tap = TPclass;
Syn = SYclass;
Exc = AVclass;
Tg = TGclass;
Oxl = OXclass;
Pss = PSclass;
Svc = SVclass;
Statcom = STclass;
Tcsc = TCclass;
Sssc = SSclass;
Upfc = UPclass;
Hvdc = HVclass;

if ~command_line_psat
  set(hdlp,'XData',[8 8 305 305 8])
  drawnow
end

Mass = DSclass;
SSR = SRclass;
Rmpg = RGclass;
Rmpl = RLclass;
Rsrv = RSclass;
Vltn = VLclass;
Ypdp = YPclass;
Pod = POclass;
COI = CIclass;

if ~command_line_psat
  set(hdlp,'XData',[8 8 338 338 8])
  set(htxt,'String','Initializing Simulink Library...')
  drawnow
end

% load PSAT Simulink library
if Settings.matlab && Settings.hostver >= 7
  if ~exist('load_system')
    if exist('simulink') ~= 5
      fm_disp('* * Simulink cannot be found on your system.')
      fm_disp('* * The PSAT-Simulink will not be available.')
    else
      fm_disp('* * Problems in loading the PSAT Simulink Library.')
    end
  else
    load_system('fm_lib')
  end
end

if failed,
  disp(' '), disp('PSAT is not properly initialized.')
else,
  if ~command_line_psat, fm_main, end
end

if ~command_line_psat, close(hdl), end

clear failed hdl hdlp a count fid nname sline tipi ncomp
clear psatver psatdate psatdir lipdir command_line_psat htxt

% ----------------------------------------------------------- %
%                       W A R N I N G                         %
% ----------------------------------------------------------- %
% Following lines were written by the UDM build utility.      %
% This utility requires you do NOT change anything beyond     %
% this point in order to be able to correctly install and     %
% uninstall UDMs.                                             %
% ----------------------------------------------------------- %

Sofc = FCclass;
Cac = CCclass;
Cluster = CLclass;
Exload = ELclass;
Phs = PHclass;
Wind = WNclass;
Cswt = CSclass;
Dfig = DFclass;
Ddsg = DDclass;
Busfreq = BFclass;
Pmu = PMclass;
Jimma = JIclass;
Mixload = MXclass;
WTFR = WTFRclass;
Spv = SPVclass;
Spq = SPQclass;
